<?php
/**
 * Created by Zhy
 * User: Zhy
 * Date: 2020/5/8
 * Time: 17:17
 */

namespace app\api\controller;


use think\Db;

class Banner extends Base
{
    /**
     * 异地登录验证
     * @return string
     */
    public function __construct()
    {
        $user_id = input('user_id');
        $time = input('time');
        $value = input('value');
        $reqKey = input('reqKey');
        $auth = $this->checkAll($user_id,$time,$value,$reqKey);
        if($auth == 112){
            echo json_encode(['status'=>301,'msg'=>$this->otherLogin]);
            exit;
        }elseif($auth == 110){
            echo json_encode(['status' => 302, 'msg' => $this->frost]);
            exit;
        }elseif($auth == 2111){
            echo json_encode(['status' => 303, 'msg' => $this->del]);
            exit;
        }
    }
    
    /**
     * 轮播图
     * @return \think\response\Json
     * banner_cate   0 全部   1 帆船  2 赛艇
     */
    public function bannerList(){
        $banner_cate = input('banner_cate');
        $where['banner_status'] = 1;
        if(isset($banner_cate) && $banner_cate != 0){
            $where['banner_cate'] = $banner_cate;
        }
        $banner = Db::table('up_banner')
            ->where($where)
            ->field('banner_id, banner_name, banner_thumb, banner_type, banner_match_id, banner_link, 
            banner_content')
            ->order('banner_sort asc')
            ->limit(5)
            ->select();
        foreach($banner as $k => $v){
            if($v['banner_type'] == 2){
                $match = Db::table('up_match')
                    ->field('match_cate, match_status')
                    ->where('match_id', $v['banner_match_id'])
                    ->find();
                $banner[$k]['match_cate'] = $match['match_cate'];
                $banner[$k]['match_status'] = $match['match_status'];
            }
        }
        if($banner){
            return json(['status' => 200, 'msg' => $banner]);
        }else{
            return json(['status' => 200, 'msg' => []]);
        }
    }
    
    /**
     * 轮播详情
     * @return \think\response\Json
     * banner_id    轮播ID
     */
    public function bannerDetail(){
        $banner_id = input('banner_id');
        $banner = Db::table('up_banner')
            ->where('banner_id', $banner_id)
            ->field('banner_match_id, banner_link, banner_contente')
            ->find();
        return json(['status' => 200, 'msg' => $banner]);
    }
}